package com.yan.domain;

import java.util.Arrays;

public class MyArrayUtillmpl extends MyArrayUtil {

    @Override
    public void findAll(int[] arr) {
        System.out.println(Arrays.toString(arr));
    }

    @Override
    public int findIndex(int[] arr, int index) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == index) {
                return i;
            }
        }
        return -1;
    }

    @Override
    public void arrayInversion(int[] arr) {
        for (int i = 0, j = arr.length - 1; i < arr.length / 2; i++, j--) {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }

    @Override
    public int[] deletArray(int[] arr, int index) {
        int[] newArr = new int[arr.length - 1];
        int num = -1;
        for (int i = 0; i < arr.length - 1; i++) {
            newArr[i] = arr[i];
            if (arr[i] == index) {
                num = i;
                break;
            }
        }
        if(num != -1) {
            for (int i = num; i < arr.length - 1; i++) {
                newArr[i] = arr[i + 1];
            }
        }
        return newArr;
    }
}
